package com.hgxd.exception;


import com.hgxd.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author wtf
 * @create 2023-07-12 17:02
 * @description :
 */
@ControllerAdvice
@Slf4j
public class MyExceptionHandler {
    /**
     * 如果抛出的是ServiceException，则调用该方法
     *
     * @param se 业务异常
     * @return
     */
    @ExceptionHandler(ServiceException.class)
    @ResponseBody
    public Result<String> handle(ServiceException se) {

        log.error(se.getMessage());
        return Result.fail(se.getMessage(), se.getResultCodeEnum());
    }

}
